package com.jzo2o.market.controller.operation;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.market.model.dto.request.ActivityQueryForPageReqDTO;
import com.jzo2o.market.model.dto.request.ActivitySaveReqDTO;
import com.jzo2o.market.model.dto.response.ActivityInfoResDTO;
import com.jzo2o.market.service.IActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author XingDong
 */
@Slf4j
@RestController
@RequestMapping("/operation/activity")
@Api(tags = "运营端 - 优惠券活动")
public class ActivityController {

    @Resource
    private IActivityService activityService;

    @PostMapping("/save")
    @ApiOperation("保存优惠券活动，和修改共用一个接口")
    public void add(@Valid @RequestBody ActivitySaveReqDTO dto) {
        dto.check();
        activityService.add(dto);
    }

    @GetMapping("/page")
    @ApiOperation("分页查询优惠券活动")
    public PageResult<ActivityInfoResDTO> page(ActivityQueryForPageReqDTO dto) {
        return activityService.findByPage(dto);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询优惠券活动详情")
    @ApiImplicitParam(name = "id", value = "优惠券活动id", required = true, dataTypeClass = Long.class)
    public ActivityInfoResDTO findById(@PathVariable Long id) {
        return activityService.findById(id);
    }

    //撤销优惠券活动
    @PostMapping("/revoke/{id}")
    @ApiOperation("撤销优惠券活动")
    @ApiImplicitParam(name = "id", value = "优惠券活动id", required = true, dataTypeClass = Long.class)
    public void revoke(@PathVariable Long id) {
        activityService.revoke(id);
    }
}
